//
//  BaseViewController.swift
//

import UIKit

class BaseViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = UIColor.sysBackground
        
        addBackBtn()
    }
    
    deinit {
        debugPrint("deinit: \(classForCoder)")
    }
    
    private func addBackBtn() {
        if let childrens = navigationController?.children, childrens.count > 1 {
            let btn = UIButton(frame: CGRect(x: 0, y: 0, width: 40, height: 40))
            btn.contentHorizontalAlignment = .left
            btn.setImage("default_back".image, for: .normal)
            btn.addTarget(self, action: #selector(backBtnClick), for: .touchUpInside)
            navigation.item.leftBarButtonItem = UIBarButtonItem(customView: btn)
        }
    }

    @objc private func backBtnClick() {
        goBack()
    }
}
